package com.erp.myAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.erp.bean.TouSuBean;
import com.erp.R;
import com.erp.util.Myutil;
import com.erp.util.Sputil;

import java.util.List;

/**
 * Created by Administrator on 2018/2/3/003.
 * 作者：刘洋
 */

public class TouSuphotoAdapter extends BaseAdapter{
    private List<TouSuBean.photo> mlist;
    private Context mcontext;
    private LayoutInflater minflater;
    private boolean isadd=false;
    int width=0;
    public TouSuphotoAdapter(List<TouSuBean.photo> list, Context context) {
        super();
        this.mlist = list;
        this.mcontext = context;
        this.minflater = LayoutInflater.from(context);
        width=Sputil.sp("erp").getInt("width",width);
    }
    @Override
    public int getCount() {
        return mlist.size()+1;
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView=minflater.inflate(R.layout.lv_iv_item,null);
        ImageView iv= (ImageView) convertView.findViewById(R.id.iv_item);
        LinearLayout.LayoutParams params= (LinearLayout.LayoutParams) iv.getLayoutParams();
        params.height=width/3;
        iv.setLayoutParams(params);
        if(position==mlist.size()){
            if(isadd) {
                iv.setImageResource(R.mipmap.erp_photo);
            }else{
                iv.setVisibility(View.GONE);
            }
        }else {
            Myutil.showhttpphoto(mlist.get(position).uri, iv, mcontext);
        }
        return convertView;
    }
    public void isadd(boolean isadd){
        this.isadd=isadd;
        notifyDataSetChanged();
    }
    public void notifyA(List<TouSuBean.photo> list){
        this.mlist=list;
        notifyDataSetChanged();
    }
}
